package com.zzx;

import com.zzx.model.Student;
import com.zzx.model.Teacher;

public class MyTest {

	public static void main(String[] args) throws CloneNotSupportedException {
		//定义对象 Student
		Student s1 = new Student();
		s1.setId("11");
		s1.setName("小明");
		s1.setAge(18);
		s1.setSex("男");
		
		Teacher t1 = new Teacher();
		t1.setName("老师11");
		t1.setAge(44);
		t1.setStudent(s1);
		
		Teacher t2 = t1.clone();
		Student s2 = t2.getStudent();
		s2.setName("aa");
		System.out.println("**原生：" + t1.toString());
		System.out.println("**克隆：" + t2.toString());
		//浅克隆的输出结果：总结：当修改t2对象的 s2对象时， t1 对象里面的student也会随之修改。
//		**原生：teacher[ name=老师11 ,age 44, student[ id=11 , name=aa , sex=男 ,age=18] ]
//		**克隆：teacher[ name=老师11 ,age 44, student[ id=11 , name=aa , sex=男 ,age=18] ]
		
		//深克隆输出结果：总结，当修改对象s2的时候只有克隆t2对象里面的student被修改，原有对象并没有被修改
		//**原生：teacher[ name=老师11 ,age 44, student[ id=11 , name=小明 , sex=男 ,age=18] ]
		//**克隆：teacher[ name=老师11 ,age 44, student[ id=11 , name=aa , sex=男 ,age=18] ]

	}

}
